﻿using System;
using System.Data;
using FirebirdSql.Data.FirebirdClient;


namespace ik.DB.Firebird
{
    public class clDbFB : clDB
    {
        #region "ToString"
        /// <summary>
        /// class information
        /// </summary>
        /// <returns>String</returns>
        public override String ToString()
        {
            return "Class name: ik.DB.Firebird \n\n" +
                   "Class version: " + Environment.Version.ToString() + "\n" +
                   "OS version: " + Environment.OSVersion.ToString() + "\n" +
                   "Computer name: " + Environment.MachineName + "\n" +
                   "Rights: (c) 2011 - by Ivan Kruger";
        }
        #endregion

        /// <summary>
        /// contrutor
        /// </summary>
        public clDbFB()
            : base(enSGBD.Firebird)
        {
        }

        #region "GetCnn"
        /// <summary>
        /// conecta ao banco de dados Firebird
        /// </summary>
        /// <param name="user">nome do usuario</param>
        /// <param name="pwd">senha do usuario encriptada</param>
        /// <param name="pathDB">caminho do arquivo FDB</param>
        /// <param name="ipDatabase">ip do cliente com o banco</param>
        /// <param name="porta">numero da porta : 3050</param>
        public void GetCnn(String user, String pwd, String pathDB, String ipDatabase, String porta)
        {
            try
            {
                cnnString = "User={0};Password={1};Database={2};DataSource={3};Port={4};Dialect=3;Charset=NONE;Role=;Connection lifetime=15;Pooling=true;MinPoolSize=0;MaxPoolSize=50;Packet Size=8192;ServerType=0;";
                cnnString = String.Format(cnnString,
                                user,
                                ik.FunctionsDB.clFunctionsDB.CrypTo2(pwd, FunctionsDB.enEncryption.Descriptar),
                                pathDB,
                                ipDatabase,
                                porta);

                if (cnnDB == null)
                    cnnDB = new FbConnection(cnnString);
                if (cnnDB.State != ConnectionState.Open)
                    cnnDB.Open();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
    }

}

